package priv.pfz.basedao.lab.performance;

import com.google.common.collect.Lists;

import java.lang.reflect.Field;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * @author yyjxp
 * 2024/8/4 15:33
 */
public class ReflectField implements ReflectTest {
    private final List<Field> fields;

    public ReflectField() {
        fields = Lists.newArrayList(TestBean.class.getDeclaredFields());
        assertEquals(10, fields.size());
    }

    @Override
    public String name() {
        return "反射访问字段";
    }

    @Override
    public void run(TestBean bean) {
        for (Field field : fields) {
            try {
                field.get(bean);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
